//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.rpt;

import com.aidong.dao.wills.MemberContractDao;
import com.aidong.model.wills.MemberContract;
import com.aidong.util.ExportXls;
import com.aidong.web.controller.BaseController;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import jxl.format.Alignment;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"cardPriceChange"})
public class CardPriceChangeController extends BaseController {
    @Resource
    MemberContractDao memberContractDao;

    public CardPriceChangeController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        return (new ModelAndView("rpt/cardprice/list")).addObject("dt1", sdf.format(new Date(System.currentTimeMillis() - 86400000L))).addObject("dt2", sdf.format(new Date()));
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Object list = null;
        ModelAndView mv = new ModelAndView("rpt/cardprice/_list");
        mv.addObject("list", list);
        return mv;
    }

    @RequestMapping({"expt"})
    public ModelAndView expt(@RequestParam(value = "shopCode",required = false) String shopCode, @RequestParam(value = "dateFrom",required = false) String dateFrom, @RequestParam(value = "dateTo",required = false) String dateTo, HttpServletResponse response) {
        try {
            String[] e = new String[]{"01", "02", "03"};
            int[] pp = new int[]{1, 2, 3, 4, 5, 6};
            HashMap dm = new HashMap();
            int n = 0;
            String[] map = e;
            int xls = e.length;

            for(int sheet = 0; sheet < xls; ++sheet) {
                String cellFormat = map[sheet];
                int[] i$ = pp;
                int o = pp.length;

                for(int i$1 = 0; i$1 < o; ++i$1) {
                    int p = i$[i$1];
                    dm.put(cellFormat + "_" + p, Integer.valueOf(n++));
                }
            }

            LinkedHashMap var20 = new LinkedHashMap();
            Object[] var29;
            if(!this.chkNull(dateFrom) && !this.chkNull(dateTo)) {
                List var21 = this.memberContractDao.getCardPriceList(this.getDateFrom(dateFrom), this.getDateTo(dateTo));
                Iterator var23 = var21.iterator();

                while(var23.hasNext()) {
                    MemberContract var25 = (MemberContract)var23.next();
                    Integer var27 = (Integer)dm.get(var25.getCardType() + "_" + var25.getValids());
                    if(var27 != null) {
                        var29 = (Object[])var20.get(var25.getShopCode());
                        if(var29 == null) {
                            var29 = new Object[dm.size() * 3 + 2];
                            var29[0] = var25.getShopCode();
                            var29[1] = this.cache.getValue("shopName", var25.getShopCode());
                            var20.put(var25.getShopCode(), var29);
                        }

                        var29[var27.intValue() * 3 + 2] = var25.getTotalPrice();
                        var29[var27.intValue() * 3 + 3] = var25.getFactPrice();
                        var29[var27.intValue() * 3 + 4] = Double.valueOf(var25.getTotalPrice().doubleValue() - var25.getFactPrice().doubleValue());
                    }
                }
            }

            ExportXls var22 = new ExportXls(response, "卡价变动差异", "卡价变动差异");
            var22.addHead(new String[0]);
            var22.addHead(new String[0]);
            WritableSheet var24 = var22.getSheet();
            WritableCellFormat var26 = new WritableCellFormat();
            var26.setAlignment(Alignment.CENTRE);

            for(int i = 0; i < e.length; ++i) {
                var24.addCell(new Label(i * pp.length * 3 + 2, 0, this.cache.getValue("cardCategory", e[i]), var26));
                var24.mergeCells(i * pp.length * 3 + 2, 0, (i + 1) * pp.length * 3 + 1, 0);

                for(int j = 0; j < pp.length; ++j) {
                    var24.addCell(new Label((i * pp.length + j) * 3 + 2, 1, pp[j] + "年卡", var26));
                    var24.mergeCells((i * pp.length + j) * 3 + 2, 1, (i * pp.length + j + 1) * 3 + 1, 1);
                    var24.addCell(new Label((i * pp.length + j) * 3 + 2, 2, "原价"));
                    var24.addCell(new Label((i * pp.length + j) * 3 + 3, 2, "新价"));
                    var24.addCell(new Label((i * pp.length + j) * 3 + 4, 2, "变动"));
                }
            }

            var22.addHead(new String[]{"门店编号", "门店名称"});
            var22.setWidth(new int[]{10, 15});
            Iterator var28 = var20.values().iterator();

            while(var28.hasNext()) {
                var29 = (Object[])var28.next();
                var22.addRow(var29);
            }

            var22.close();
            this.addUserLog("导出卡价变动差异", var20.size() + "条记录");
        } catch (Exception var19) {
            this.log.error("import", var19);
        }

        return null;
    }
}
